<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <li :class="{completed:item.isDone}" v-for="item in showArr" :key="item.id">
      <div class="view">
        <input class="toggle" type="checkbox" v-model="item.isDone"/>
        <label>{{item.name}}</label>
        <button class="destroy" @click="delFn(item.id)"></button>
      </div>
    </li>
  </ul>
  
</template>

<script>
export default {
  computed:{
    list(){
      return this.$store.state.list
    },
    showArr(){
      if(this.$store.state.isSel==='yes'){
        return this.$store.state.list.filter(item=>item.isDone);
      }else if(this.$store.state.isSel==='no'){
        return this.$store.state.list.filter(item=>!(item.isDone));
      }else{
         return this.$store.state.list
      }
    }
  },
  methods:{
    delFn(theId){
      this.list1=JSON.parse(JSON.stringify(this.list))
      let index = this.list1.findIndex(obj => obj.id === theId)
      this.list1.splice(index, 1)
      this.$store.commit('updateList',this.list1)
    }
  }
}
</script>
